<template>
  <div>
    <Searchbar>
      <el-input @change="getList" v-model="search.userid" placeholder="请输入用户ID"></el-input>
      <el-input @change="getList" v-model="search.username" placeholder="请输入用户名"></el-input>
      <el-autocomplete
        class="inline-input"
        v-model="selectedSchool"
        :fetch-suggestions="querySchool"
        placeholder="请输入学校名称"
        @select="selectSchool"
      ></el-autocomplete>
      <el-autocomplete
        class="inline-input"
        v-model="selectedCollege"
        :fetch-suggestions="queryCollege"
        placeholder="请输入学院名称"
        @select="selectCollege"
      ></el-autocomplete>
      <el-autocomplete
        class="inline-input"
        v-model="selectedMajor"
        :fetch-suggestions="queryMajor"
        placeholder="请输入专业名称"
        @select="selectMajor"
      ></el-autocomplete>
      <el-autocomplete
        class="inline-input"
        v-model="selectedClass"
        :fetch-suggestions="queryClass"
        placeholder="请输入班级名称"
        @select="selectClass"
      ></el-autocomplete>
      <el-select @change="onStatusChange" v-model="search.status" placeholder="请选择用户状态">
        <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <el-button class="search-btn" @click="getList" type="primary">查询</el-button>
    </Searchbar>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column fixed="left" type="selection" width="55"></el-table-column>
      <el-table-column fixed="left" type="index" label="序号" width="55"></el-table-column>
      <el-table-column prop="userid" label="用户ID"></el-table-column>
      <el-table-column prop="username" label="用户名"></el-table-column>
      <el-table-column prop="school_name" label="学校名称"></el-table-column>
      <el-table-column prop="college_name" label="学院名称"></el-table-column>
      <el-table-column prop="major_name" label="专业名称"></el-table-column>
      <el-table-column prop="class_name" label="班级名称"></el-table-column>
      <el-table-column prop="statusLabel" label="状态"></el-table-column>
      <el-table-column prop="create_time" label="创建时间"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            @click="onShowDetail(scope.row)"
            size="small"
            class="text-button"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next, jumper"
      @current-change="handleCurrentChange"
      @size-change=handleSizeChange
      :current-page.sync="search.page"
      :page-size="search.page_size"
      :total="total"
    ></el-pagination>
  </div>
</template>
<script>
import CreateFilter from "@/mixins/CreateFilter";
import pageMixin from "@/mixins/pageMixin";
import { studentModel } from "@/api/models";
import Searchbar from "@/components/Searchbar";
export default {
  mixins: [CreateFilter, pageMixin],
  components: { Searchbar},
  data() {
    return {
      tableData: [],
      total: 0,
      search: {
        userid: null,
        username: null,
        selectedschool_id: null,
        selectedcollege_id: null,
        selectedmajor_id: null,
        selectedclass_id: null,
        status: null,
        page: 1,
        page_size: 10,
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    onShowDetail(row) {
      this.$router.push('/student/' + row.userid);
    },
    getList() {
      console.log("getList");
      studentModel.list(
        this.search,
        (res) => {
          this.total = res.total_records;
          this.tableData = res.data.map((v) => {
            v.statusLabel = this.statusToLabel(v.status)
            return v;
          });
        },
        (err) => {
          console.log(err);
        }
      );
    },
  },
};
</script>
<style lang="scss">
</style>